<?php if(get('ini_mrela')){
	$post_num = get('ini_postnum');
	$tmp_post = $post;
	$tags = ''; $i = 0;
	echo "<section><div class=\"m-t\">相关文章</div><ul class=\"clear\">";
	if ( get_the_tags( $post->ID ) ){
		foreach ( get_the_tags($post->ID) as $tag )
		$tags.= $tag->name.',';
		$tags = strtr(rtrim($tags, ','), ' ', '-');
		$myposts = get_posts( 'numberposts='.$post_num.'&tag='.$tags.'&exclude='.$post->ID );
		foreach( $myposts as $post ){
			setup_postdata($post);
			echo post_list();
			$i ++;
		}
	}
	if ( $i < $post_num ){
		$post = $tmp_post; setup_postdata($post);
		$cats = '';
		$post_num -= $i;
		foreach ( get_the_category( $post->ID ) as $cat )
		$cats.= $cat->cat_ID.',';
		$cats = strtr(rtrim($cats, ','), ' ', '-');
		$myposts = get_posts( 'numberposts='.$post_num.'&category='.$cats.'&exclude='.$post->ID );
		foreach( $myposts as $post ){
			setup_postdata($post);
			echo post_list();
			$i ++;
		}
	}
	if ( $i < $post_num ){
		$post_num -= $i;
		$myposts = get_posts( 'numberposts='.$post_num.'&orderby=rand&exclude='.$post->ID );
		foreach( $myposts as $post ){
			setup_postdata($post);
			echo post_list();
		}
	}
	$post = $tmp_post;
	setup_postdata($post);
echo "</ul></section>";
}

function post_list(){
	global $post;
	echo "<li><a href=\"".get_permalink()."\">".get_the_title()."</a></li>";
}